package cn.sc.allinpay.allfavour.business.common.adapter;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import cn.pai.common.adapter.BaseRecyAdapter;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.business.common.data.TransRecord;

/**
 * description：收银台交易流水 适配器
 * author：pany
 * on 2018/7/17 15:02
 */
public class CashierTransAdapter extends BaseRecyAdapter<CashierTransAdapter.MyViewHoder, TransRecord> {

    @Override
    public int layoutId() {
        return R.layout.item_cashier_trans;
    }

    @Override
    public MyViewHoder onCreateViewHolder(View view) {
        return new MyViewHoder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHoder holder, int position, TransRecord data) {
        holder.tvNumber.setText(String.valueOf((++position)) + ". ");
        holder.tvTransNo.setText(data.getOrderId());
        holder.tvAmt.setText(data.getTransAmt());
        holder.tvTrsTime.setText(data.getTransDate() + "-" + data.getTransTime());
        String stateText = null;
        //支付状态  1:支付中 2:支付成功(全单支付完成) 3:撤销中(尚有其他子订单尚未撤销成功的) 4:撤销成功(全单撤销完成)

        if (data.getState() == 0) {
            stateText = "待支付";
        }
        else if (data.getState() == 1) {
            stateText = "支付中";
        } else if (data.getState() == 2) {
            stateText = "支付成功";
        } else if (data.getState() == 3) {
            stateText = "撤销中";
        } else if (data.getState() == 4) {
            stateText = "撤销成功";
        }
        //0:无抵扣(普通交易) 1:部分抵扣成功  2:抵扣撤销 3:全额抵扣成功 4：全额抵扣撤销
        if (data.getSellState() == 3) {
            stateText = "全额抵扣成功";
        } else if (data.getSellState() == 4) {
            stateText = "全额抵扣撤销";
        }
        holder.tvTrsState.setText(stateText);
    }

    class MyViewHoder extends RecyclerView.ViewHolder {

        AppCompatTextView tvNumber;//序号
        AppCompatTextView tvTransNo;//交易流水
        AppCompatTextView tvAmt;//交易金额
        AppCompatTextView tvTrsTime;//交易时间
        AppCompatTextView tvTrsState;//状态


        public MyViewHoder(View itemView) {
            super(itemView);
            // TODO Auto-generated constructor stub
            tvNumber = itemView.findViewById(R.id.tvNumber);
            tvTransNo = itemView.findViewById(R.id.tvTransNo);
            tvAmt = itemView.findViewById(R.id.tvAmt);
            tvTrsTime = itemView.findViewById(R.id.tvTrsTime);
            tvTrsState = itemView.findViewById(R.id.tvTrsState);
        }
    }
}
